package net.hserver.sync.controller.system;

import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.server.util.JsonResult;
import cn.hserver.plugin.web.annotation.Controller;
import cn.hserver.plugin.web.annotation.POST;
import cn.hserver.plugin.web.interfaces.HttpRequest;
import net.hserver.sync.bean.ReqLoginUser;
import net.hserver.sync.bean.ResLoginUser;
import net.hserver.sync.config.AdminInfo;

@Controller(value = "/sync/")
public class LoginController {
    @Autowired
    private AdminInfo adminInfo;

    @POST("login")
    public JsonResult login(HttpRequest request, ReqLoginUser reqLoginUser) {
        try {
            //校验是否是后台用户
            if (adminInfo.getUsername().equals(reqLoginUser.getUsername())
                    && adminInfo.getPassword().equals(reqLoginUser.getPassword())) {
                return JsonResult.ok("登录成功").put("data", new ResLoginUser(adminInfo));
            } else {
                return JsonResult.error("登录失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }
}
